package com.hitqz.robot.biz.websocket.config;

import com.hitqz.robot.common.security.service.RobotUser;
import com.hitqz.robot.common.security.util.SecurityUtils;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CustomConfigurator extends ServerEndpointConfig.Configurator {

	@Override
	public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
		RobotUser user = SecurityUtils.getUser();
		log.debug("[ws]{}-{},handshake", user.getId(),user.getName());
		sec.getUserProperties().put("user", user);
	}
}
